home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 897 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.6 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: kanze@gabi-soft.fr (J. Kanze)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Quick questions
  5. Date: 28 Mar 1996 09:31:19 PST
  6. Organization: GABI Software, Sarl.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <KANZE.96Mar28102433@gabi.gabi-soft.fr>
  9. References: <4j5b26$1e7a@mule1.mindspring.com> <4j7a64$l9i@engnews1.Eng.Sun.COM>
  10.     <4jajk2$17aq@mule1.mindspring.com>
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. X-Original-Date: 28 Mar 1996 09:24:33 GMT
  13. In-Reply-To: abell@mindspring.com's message of 27 Mar 1996 15:46:56 GMT
  14. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  15.     iQBVAwUBMVrM6Uy4NqrwXLNJAQHJfgH/SsWrCD8cbqOdf6iYa2Rq+I80Hly4E55w
  16.     yHk4SBicgvldmKLtF/zXqfBqt3hIlFAEb7hsKZYPofFH9kret75IRQ==
  17.     =Hkye
  18. Originator: austern@isolde.mti.sgi.com
  19.  
  20. In article <4jajk2$17aq@mule1.mindspring.com> abell@mindspring.com
  21. (Andrew Bell) writes:
  22.  
  23. |> clamage@Eng.sun.com (Steve Clamage) wrote [but much edited by me]:
  24. |> >In article 1e7a@mule1.mindspring.com, abell@mindspring.com (Andrew Bell) writes:
  25. |> >>About casting operators]
  26. |> >[[Are you asking] can you define
  27. |> >a conversion operator from a user-defined class to a predefined type
  28.  
  29. |> No, I'd want to go the other way.  In the case of "pure wrapper"
  30. |> classes (as I defined in my earlier post), one might want an automatic
  31. |> cast from the original to the wrapper.  In my case, I have created a
  32. |> class to wrap around an OS-defined struct, to give it access safety
  33. |> (the particular class contains a type specifier and a union) and
  34. |> smarter access as well as constructors.
  35.  
  36. You have it the other way.  The conversion operator is called a
  37. constructor.  Thus, to take a concrete example (based on the deleted
  38. parts of your posting (`stat' is a struct defined by Posix):
  39.  
  40.     class FileStat : stat
  41.     {
  42.     public :
  43.                         FileStat( stat const& other ) ;
  44.         //  ...
  45.     } ;
  46.  
  47. If you have a (C) struct stat, it will convert automatically to a
  48. FileStat.  (You can pass it to a function expecting a FileStat, for
  49. example.)
  50. -- 
  51. James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
  52. GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
  53. Conseils en informatique industrielle --
  54.                             -- Beratung in industrieller Datenverarbeitung
  55. ---
  56. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  57.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  58.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  59.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  60.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  61. ]
  62.